
package clases.matriculacion;

/**
 *
 * @author RICHARD
 */
import CapaDatos.DataSource;
import CapaDatos.Sql;
import clases.incio.ButtonEditor;
import clases.incio.ButtonRenderer;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Academico {
    private String cedulaAcademico;
    private String tipoAcademico;
    private String descripcionAcademico;
    private final DataSource dt;
    private String sql;  

    public Academico() {
       dt=new DataSource();
    }

    public String getCedulaAcademico() {
        return cedulaAcademico;
    }

    public void setCedulaAcademico(String cedulaAcademico) {
        this.cedulaAcademico = cedulaAcademico;
    }

    public String getTipoAcademico() {
        return tipoAcademico;
    }

    public void setTipoAcademico(String tipo) {
        this.tipoAcademico = tipo;
    }

    public String getDescripcionAcademico() {
        return descripcionAcademico;
    }

    public void setDescripcionAcademico(String descripcion) {
        this.descripcionAcademico = descripcion;
    }
    
    private int MaxIdAcademico(){
     return Sql.getMax("IDACADEMICO","ACADEMICO", true);
    }
	
   public void guardarAcademico() {
        sql="INSERT INTO ACADEMICO VALUES('"+this.MaxIdAcademico()
                + "','" + this.cedulaAcademico + "','" + tipoAcademico + "', "
                + "'"+descripcionAcademico+"')";
        Sql.insertar(sql);
   }
   public void eliminarAcademico(){
   sql="DELETE FROM ACADEMICO WHERE CEDULARUC='"+this.cedulaAcademico+"'";
   Sql.eliminar(sql);
   }
   /*public void actualizarAcademico(){
     sql="UPDATE ACADEMICO SET CEDULARUC='"+this.cedulaAcademico+"', "
            + "TIPO='"+this.tipoAcademico+"', "
            + "DESCRIPCION='"+this.descripcionAcademico+"', "
            + "WHERE CEDULARUC='"+this.cedulaAcademico+"'";
     Sql.actualizar(sql);
    
    }*/
   
    public void llenardatosAcademicos(DefaultTableModel modelo, JTable tabla){
    sql="SELECT * FROM ACADEMICO JOIN ALUMNO "
         + "ON ALUMNO.CEDULARUC=ACADEMICO.CEDULARUC "
         + "WHERE ALUMNO.CEDULARUC='"+cedulaAcademico+"'";
     // System.out.println(sql);
    Sql.getConsulta(sql, dt);
     String []fila;
  
    while(dt.next()){
    fila=new String[4];
    fila[0]=dt.getString(3);
    fila[1]=dt.getString(4);
       
    tabla.getColumnModel().getColumn(2).setCellRenderer(new ButtonRenderer());
    tabla.getColumnModel().getColumn(2).setCellEditor(
    new ButtonEditor(new JCheckBox(), modelo, tabla));
  
    modelo.addRow(fila);
   
      }
    }     
   
}
